package com.finance.report.controller;

import com.finance.framework.controller.BaseController;
import com.finance.framework.controller.Result;
import com.finance.framework.lang.Page;
import com.finance.framework.lang.PageResultBO;
import com.finance.report.bean.pojo.OrganizationSalary;
import com.finance.report.bean.pojo.OrganizationSalaryList;
import com.finance.report.export.OrganizationSalaryParse;
import com.finance.report.export.OrganizationSalaryParseBean;
import com.finance.report.request.OrganizationSalaryListReq;
import com.finance.report.service.IOrganizationSalaryService;
import com.finance.util.export.ExportBuilder;
import com.finance.util.export.ExportFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


/**
 * @Author: lijinguo
 * 供货商月结报表
 */
@Controller
@RequestMapping("/report/organizationsalary")
public class OrganizationSalaryController extends BaseController {
    @Resource
    private IOrganizationSalaryService organizationSalaryService;

    @RequestMapping("/index.htm")
    public String index(){
        return "report/organizationsalary/index";
    }

    @RequestMapping("/list")
    public Result list(OrganizationSalaryListReq form){
        Page page = Page.getInstance(form);
        OrganizationSalaryList organizationSalary = new OrganizationSalaryList();
        organizationSalary.setOrganizationCode(form.getOrganizationCode());
        organizationSalary.setSalaryMonth(form.getMonth());
        page.setParams(organizationSalary);
        PageResultBO<OrganizationSalary> resultBO = organizationSalaryService.listByPage(page);
        return getSuccessResult(resultBO);
    }
    @RequestMapping("/export")
    public void export(OrganizationSalaryListReq form, HttpServletResponse response){
        Page page = Page.getInstance(form);
        OrganizationSalaryList organizationSalary = new OrganizationSalaryList();
        organizationSalary.setOrganizationCode(form.getOrganizationCode());
        organizationSalary.setSalaryMonth(form.getMonth());
        page.setParams(organizationSalary);
        page.setLoadAll(true);
        PageResultBO<OrganizationSalary> resultBO = organizationSalaryService.listByPage(page);
        try {
            ExportBuilder builder=new ExportBuilder
                    (OrganizationSalaryParseBean.class,
                            new OrganizationSalaryParse()
                    );
            ExportFactory factory= ExportFactory.getExportFactory(
                    builder );
               factory.setDataList(resultBO.getDataList()).outPut(response);

        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
    }

}
